const { Sequelize, DataTypes } = require('sequelize');
const seq = require('../db/sequelize');

const Order = seq.define('order', {
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: "用户ID"
    },
    address_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: "收货地址ID"
    },
    goods_info: {
        type: DataTypes.STRING,
        allowNull: false,
        comment: "商品信息"
    },
    total: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: false,
        comment: "订单总金额"
    },
    order_code: {
        type: DataTypes.CHAR(15),
        allowNull: false,
        comment: "订单号"
    },
    status: {
        type: DataTypes.ENUM('0', '1', '2', '3', '4'), // 使用 ENUM 类型来定义状态
        allowNull: false,
        comment: "订单状态(0:未支付. 1:已支付, 2:已发货, 3:已签收, 4:取消)"
    }
});

// // 同步模型
// Order.sync({ force: true })
//     .then(() => {
//         console.log('Order table has been created');
//     })
//     .catch((error) => {
//         console.error('Error creating table:', error);
//     });

module.exports = Order;